package com.junzhiit.nengji.cms.web.vo;

import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

import com.bainaeco.framework.base.BaseObject;

public class AreaTreeVO extends BaseObject{

	private static final long serialVersionUID = 7965881123790475040L;

	private String id;
	
	private Integer cityId;

	private Integer level;
	
	private String label;

	private Integer parentId;
	
	private List<AreaTreeVO> children;
	
	private int childrenCount;

	public int getChildrenCount() {
		return childrenCount;
	}

	public void setChildrenCount(int childrenCount) {
		this.childrenCount = childrenCount;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Integer getCityId() {
		return cityId;
	}

	public void setCityId(Integer cityId) {
		this.cityId = cityId;
	}

	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public Integer getParentId() {
		return parentId;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}

	public List<AreaTreeVO> getChildren() {
		return children;
	}

	public void setChildren(List<AreaTreeVO> children) {
		this.children = children;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}
	
	public void sortChildren() {  
		// 对本层节点进行排序  
		// 可根据不同的排序属性，传入不同的比较器，这里传入ID比较器  
		Collections.sort(this.getChildren(), new NodeIDComparator());  
		// 对每个节点的下一层节点进行排序  
		for (Iterator<AreaTreeVO> it = children.iterator(); it.hasNext();) {  
			it.next().sortChildren();  
		}  
	}
	
	class NodeIDComparator implements Comparator<AreaTreeVO> {  
		// 按照节点编号比较  
		@Override
		public int compare(AreaTreeVO o1, AreaTreeVO o2) {
			int j1 = o1.getCityId();  
			int j2 = o2.getCityId();  
			return (j1 < j2 ? -1 : (j1 == j2 ? 0 : 1));  
		}   
	}
	
}
